<?php


namespace app\api\controller\xilujob;

use app\common\model\xilujob\Area;
use app\common\controller\xilujob\XilujobApi;

/**
 * 开放城市
 */
class SiteCity extends XilujobApi
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    protected $restrictedActions = ['*'];


    /**
     * @ApiTitle    (开放城市)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/xilujob.site_city/site_cities)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", sample="{'id':'int','city_id':'int','city_name':'string'}", description="开放城市")
     */
    public function site_cities(){
        $cities = \app\common\model\xilujob\SiteCity::getAll();
        $this->success('查询成功',$cities);
    }

    /**
     * @ApiTitle    (所有城市)
     * @ApiSummary  (按照A-Z首字母排序的城市列表)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/xilujob.site_city/site_cities)
     */
    public function get_cities(){
        $lists = Area::get_cities();
        $this->success('查询成功',$lists);
    }

    /**
     * @ApiTitle (城市下的区县)
     * @ApiSummery (城市下的区县)
     * @ApiRoute (/api/xilujob.site_city/districts_with)
     * @ApiParams (name="cityid" type="int" required="true" )
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", sample="{'id':'int','city_id':'int','city_name':'string'}", description="城市下的区县列表")
     */
    public function districts_with() {
        $cityId = $this->request->param('cityid');
        if(!$cityId) {
            $this->error('参数错误');
        }
        $data = Area::getDistrictsWith($cityId);
        $this->success('查询成功',$data);
    }

}